<template>
  <div>
    <eagle-dialog-page
      :isPage="false"
      :url="url"
      :params="params"
      :title="title"
      @initList="_initList"
      @setData="setData"
      v-bind="$attrs"
      v-on="$listeners"
      ref="eagleDialogPage"
      :option="option"
      :selectedValue="selectedValue"
      :isFuzzyQuery="true"
      fuzzyKey="OrgName"
    >
      <eagle-cell v-for="(item, index) in list" :key="index">
        <div class="risk_item_radio">
          <div>
            <div class="mb-5 color-gray1">{{ item.OrgName }}</div>
            <div class="color-gray3">
              {{ item.OrgFullName }}
            </div>
          </div>
          <eagle-radio :name="item.OrgCode" @click="radioClick(item)"></eagle-radio>
        </div>
      </eagle-cell>
    </eagle-dialog-page>
    <!-- <van-search
      class="info_search"
      v-model="value"
      @search="onSearch"
      @clear="clearSearch"
      clearable
      placeholder="搜索"
    />
    <van-list
      style="margin-top: 10px"
      :finished="finished"
      v-model="loading"
      finished-text="没有更多了"
    >
      <van-radio-group @change="handleChange" v-model="result">
        <van-cell v-for="(item, index) in list" :key="index">
          <div class="risk_item_radio">
            <div>
              <div class="mb-10">{{ item.OrgName }}</div>
              <div>{{ item.OrgFullName }}</div>
            </div>
            <van-radio :name="item.OrgCode"></van-radio>
          </div>
        </van-cell>
      </van-radio-group>
    </van-list> -->
  </div>
</template>

<script>
import { getChooseTeamList } from "@/api/common";
export default {
  props: {
    title: {
      type: String,
      default: "选择班组",
    },
    orgCode: {
      type: String,
      required: false,
    },
    selectedValue: {
      type: String,
      default: () => "",
    },
  },
  data() {
    return {
      option: { name: "OrgName", code: "OrgCode" },
      url: "/UserUser/GetChooseTeamList",
      simSelectObject: { code: "", name: "" },
      params: [
        {
          page: 0,
          orgCode: this.orgCode,
          companyCode: "",

        },
      ],
      list: [],
    };
  },
  created() {
  },
  methods: {
    _initList(list) {
      this.list = list;
      var newData = [];
      newData = [{ code: this.selectedValue, OrgCode: this.selectedValue }];
        this.$refs.eagleDialogPage.initSeletedData(newData);
    },
    setData(data) {
      this.simSelectObject = data;
    },
    radioClick(item){
      let resultRadio = Object.assign({ code: "", name: "" }, item);
      resultRadio.code = item.OrgCode;
      resultRadio.name = item.OrgName;
      this.$emit("callback", resultRadio);
      this.$emit("update:show", false);
    },
    handleChange(id) {
      const newData = this.list.filter((item) => item.OrgCode === id);
      var item = {
        value: newData[0].OrgCode,
        name: newData[0].OrgName,
      };
      this.$emit("CallBack", item);
    },
    
    onSearch(keyWord) {
      if (keyWord) {
        this.list = this.fuzzyQuery(this.options, keyWord, "OrgName");
      } else {
        this.list = this.options;
      }
    },
    fuzzyQuery(list, keyWord, type) {
      var arr = [];
      list.map((item) => {
        if (item[type].indexOf(keyWord) >= 0) {
          arr.push(item);
        }
      });
      return arr;
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  height: 100vh;
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.risk_item_radio {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
